﻿
Partial Class WebForm_MainForVolunteer
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Me.Master.SiteMapPath.Provider = SiteMap.Providers("VolunteerSiteMapProvider")
            Me.BindData()
        End If
    End Sub

    Protected Sub gvToDO_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvToDO.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            'If DataBinder.Eval(e.Row.DataItem, "col1").ToString().Contains("三年內服時數累計") Then
            '    TryCast(e.Row.FindControl("lknApplyHonorCert"), LinkButton).Visible = True
            'End If

        End If
    End Sub

    Protected Sub SearchBulletin1_Loaded(ByVal source As Object, ByVal e As System.EventArgs) Handles SearchBulletin1.Loaded
        Me.SearchBulletin1.BindGV(My.UserType.Volunteer)
    End Sub

    '申請榮譽卡
    Protected Sub gvToDO_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvToDO.RowCommand
        If e.CommandName = "lknApplyHonorCert" Then
            Dim dat As New clsData
            Dim sql As New MyStringBuilder

            sql.AppendFormat("Insert into HonorCertApplication select")
            sql.AppendFormat(" '{0}'", Context.User.Identity.Name)
            sql.AppendFormat(",'{0}'", "WA")
            sql.AppendFormat(",{0}", "getdate()")
            sql.AppendFormat(",'{0}'", Context.User.Identity.Name)

            dat.AccData(sql)

            MyObj.ShowMessage(Me.GetLocalResourceObject("SaveSuccess"))
        End If
    End Sub
End Class

Partial Class WebForm_MainForVolunteer
    Private Sub BindData()
        Me.BindGVToDo()
    End Sub

    Private Sub BindGVToDo()
        Dim dat As New clsData
        Dim sql As New MyStringBuilder

        sql.AppendFormat("select ")
        sql.AppendFormat("'[志工個人]' as col1 ")
        sql.AppendFormat(",'' as col2 ")

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'身份:' as col1 ")
        sql.AppendFormat(",'{0}' ", HttpUtility.UrlDecode(Request.Cookies("UserType").Value))

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'志工年資:' as col1 ")
        sql.AppendFormat(", cast(isnull(datediff(yy,IssueDate,getdate()), 0) as varchar) as col2 ")
        sql.AppendFormat("from Volunteer v ")
        sql.AppendFormat("left join VBook vb on v.VolunteerID = vb.VolunteerID ")
        sql.AppendFormat("where v.VolunteerId='{0}' ", Page.User.Identity.Name)

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'基礎訓已上課時數:' as col1 ")
        sql.AppendFormat(",CAST(TrainingBHour as varchar) as col2 ")
        sql.AppendFormat("from volunteerstat v ")
        sql.AppendFormat("where VolunteerId='{0}' ", Page.User.Identity.Name)

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'特殊訓已上課時數:' as col1 ")
        sql.AppendFormat(",CAST(TrainingSHour as varchar) as col2 ")
        sql.AppendFormat("from volunteerstat v ")
        sql.AppendFormat("where VolunteerId='{0}' ", Page.User.Identity.Name)

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'實務訓已上課時數:' as col1 ")
        sql.AppendFormat(",CAST(TrainingWHour as varchar) as col2 ")
        sql.AppendFormat("from volunteerstat v ")
        sql.AppendFormat("where VolunteerId='{0}' ", Page.User.Identity.Name)

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'[志工服務]' as col1 ")
        sql.AppendFormat(",'' as col2 ")

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'待處理髒亂點數量:' as col1 ")
        sql.AppendFormat(",cast(count(*) as nvarchar(10)) as col2 ")
        sql.AppendFormat("from VolunteerDistinctView v ")
        sql.AppendFormat("where v.Active = '{0}' ", My.VolunteerStatus.Approving)

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'三年內服時數累計:' as col1 ")
        sql.AppendFormat(",cast(count(*) as nvarchar(10)) as col2 ")
        sql.AppendFormat("from VolunteerDistinctView v ")
        sql.AppendFormat("where v.Active = '{0}' ", My.VolunteerStatus.Approving)

        sql.AppendFormat("union all select ")
        sql.AppendFormat("'服務時數累計:' as col1 ")
        sql.AppendFormat(",cast(count(*) as nvarchar(10)) as col2 ")
        sql.AppendFormat("from VolunteerDistinctView v ")
        sql.AppendFormat("where v.Active = '{0}' ", My.VolunteerStatus.Approving)

        Me.gvToDO.DataSource = dat.GetData(sql)
        Me.gvToDO.DataBind()

    End Sub
End Class